﻿import CWinContainerInfo;
import CMenuGroup;
import CHostPanel;

class CWinContainer
{
	var Info:CWinContainerInfo;
	var MenuGroup:CMenuGroup;
	var HostPanel:CHostPanel;
	public function CWinContainer(_Info,_MenuGroup,_HostPanel)
	{
		var iInfo:CWinContainerInfo = new CWinContainerInfo();
		var iMenuGroup:CMenuGroup = new CMenuGroup();
		var iHostPanel:CHostPanel = new CHostPanel();
		Info = iInfo;
		MenuGroup = iMenuGroup;
		HostPanel = iHostPanel;
		//格式化信息
		if(_Info&&_MenuGroup&&_HostPanel)
		{
			Info.Caption =_Info.Caption;
			Info.Name=_Info.Name;
			Info.Version=_Info.Version;
			Info.BackgroundMovie = _Info.BackgroundMovie;
			MenuGroup.MenuArray = _MenuGroup.MenuArray;
			HostPanel.HostArray = _HostPanel.HostArray;
		}else
		{
			//trace("CWinContainer create failed!");
		}
	}
	public function saveSetting():Boolean
	{
		var _Caption:String = Info.getCaption();
		var Setting:SharedObject = SharedObject.getLocal(_Caption.toString());
		Setting.data._version = Info.getVersion();
		Info.updateVersion();//
		Setting.data.Info = Info;
		Setting.data.MenuGroup = MenuGroup;
		Setting.data.HostPanel = HostPanel;
		if(Setting.flush())
		{
			var mStr:String = new String("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
			for(var iM in Info)
			{
				trace(Info[iM]);
				mStr+="<node label=\""+Info[iM]+"\"></node>";
			}
			
			fscommand("SaveFile",mStr);
			//trace("saveSetting success");
			//Info.updateVersion();
			//var iTest:SharedObject = SharedObject.getLocal(_Caption);
			//var iInfo:CWinContainerInfo;
			//iInfo=iTest.data.Info;
			//trace("Info.Caption:"+iInfo.getCaption());
			return true;
		}else
		{
			trace("save setting failed");
			return false;
		}
	}
	public function setInfo(value:CWinContainerInfo):Void
	{
		Info = value;
	}
	public function getInfo():CWinContainerInfo
	{
		return Info;
	}	
	public function setMenuGroup(value:CMenuGroup):Void
	{
		MenuGroup = value;
	}
	public function getMenuGroup():CMenuGroup
	{
		return MenuGroup;
	}
	public function setHostPanel(value:CHostPanel):Void
	{
		HostPanel = value;
	}
	public function getHostPanel():CHostPanel
	{
		return HostPanel;
	}
}
